#!python
import glob
import re
files = glob.glob("./*html")
for file in files:
	nuc_EA = 0
	all_EA = 1
	nuc_UA = 0
	all_UA = 1
	nuc_UN = 0
	all_UN = 1
	nuc_O = 0
	all_O = 1
	nuc_Lt = 0
	all_Lt = 1
	nuc_SA = 0
	all_SA = 1
	nuc_AF = 0
	all_AF = 1
	nuc_EA = 0
	all_EA = 1
	hom = 0
	f = open(file, "r")
	lines = f.readlines()
	for line in lines:
		line = line.strip('\n')
		if(re.match(".*\"East Asian\": (\d+),.*?\"East Asian\": (\d+),.*?\"East Asian\": (\d+),", line)):
			a = re.match(".*\"East Asian\": (\d+),.*?\"East Asian\": (\d+),.*?\"East Asian\": (\d+),", line)
			nuc_EA += int(a.group(1))
			all_EA += int(a.group(2))
		if(re.match(".*\"European (Finnish)\": (\d+),.*?\"European (Finnish)\": (\d+),.*?\"European (Finnish)\": (\d+),", line)):
			a = re.match(".*\"European (Finnish)\": (\d+),.*?\"European (Finnish)\": (\d+),.*?\"European (Finnish)\": (\d+),", line)
			nuc_UA += int(a.group(1))
			all_UA += int(a.group(2))
		if(re.match(".*\"European (Non-Finnish)\": (\d+),.*?\"European (Non-Finnish)\": (\d+),.*?\"European (Non-Finnish)\": (\d+),", line)):
			a = re.match(".*\"European (Non-Finnish)\": (\d+),.*?\"European (Non-Finnish)\": (\d+),.*?\"European (Non-Finnish)\": (\d+),", line)
			nuc_UN += int(a.group(1))
			all_UN += int(a.group(2))
		if(re.match(".*\"Other\": (\d+),.*?\"Other\": (\d+),.*?\"Other\": (\d+),", line)):
			a = re.match(".*\"Other\": (\d+),.*?\"Other\": (\d+),.*?\"Other\": (\d+),", line)
			nuc_O += int(a.group(1))
			all_O += int(a.group(2))
		if(re.match(".*\"Latino\": (\d+),.*?\"Latino\": (\d+),.*?\"Latino\": (\d+),", line)):
			a = re.match(".*\"Latino\": (\d+),.*?\"Latino\": (\d+),.*?\"Latino\": (\d+),", line)
			nuc_Lt += int(a.group(1))
			all_Lt += int(a.group(2))
		if(re.match(".*\"South Asian\": (\d+),.*?\"South Asian\": (\d+),.*?\"South Asian\": (\d+),", line)):
			a = re.match(".*\"South Asian\": (\d+),.*?\"South Asian\": (\d+),.*?\"South Asian\": (\d+),", line)
			nuc_SA += int(a.group(1))
			all_SA += int(a.group(2))
		if(re.match(".*\"African\": (\d+),.*?\"African\": (\d+),.*?\"African\": (\d+),", line)):
			a = re.match(".*\"African\": (\d+),.*?\"African\": (\d+),.*?\"African\": (\d+),", line)
			nuc_AF += int(a.group(1))
			all_AF += int(a.group(2))
		
	print(file+"\t"+str(nuc_EA/all_EA)+"\t"+str(nuc_UA/all_UA)+"\t"+str(nuc_UN/all_UN)+"\t"+str(nuc_O/all_O)+"\t"+str(nuc_Lt/all_Lt)+"\t"+str(nuc_SA/all_SA)+"\t"+str(nuc_AF/all_AF))